﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace PasswordProvider.ViewModel.Framework
{
    /// <summary>
    /// TextEditViewModel: Encapsulates the data and business rules for a text edit view such as TextBox.
    /// Inherits from VisualViewModel and provides additional properties Text (string) and IsReadOnly (bool).
    /// </summary>
    public class TextEditViewModel : VisualViewModel
    {
        #region Events
        /// <summary>
        /// TextValueChanged event, raised whtn the text value changes.
        /// </summary>
        internal event ValueChangedEventHandler<string> TextValueChanged;

        #endregion

        #region Constrution

        internal TextEditViewModel(string displayName, string toolTip, string text)
            : this(displayName, toolTip, text, false)
        {            
        }

        internal TextEditViewModel(string displayName, string toolTip, string text, bool isReadOnly)
            : base(displayName, toolTip)
        {
            _text = text;
            _isReadOnly = isReadOnly;
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Get or set the Text.
        /// </summary>
        public string Text
        {
            get { return _text; }
            set 
            {
                if (base.SetPropertyValue(value, ref _text, "Text"))
                {
                    if (TextValueChanged != null)
                        TextValueChanged(_text);
                }
            }
        } private string _text;

        /// <summary>
        /// Get, Set text box IsReadOnly
        /// </summary>
        public bool IsReadOnly
        {
            get { return _isReadOnly; }
            set { SetPropertyValue(value, ref _isReadOnly, "IsReadOnly"); }
        } private bool _isReadOnly;


        
        #endregion

        
    }
}
